package com.ms.oschina.base;

import android.support.v4.app.Fragment;
import android.view.View;
import android.widget.FrameLayout;

import com.ms.oschina.R;
import com.ms.oschina.base.LoadingPager.ResultCode;
import com.ms.oschina.util.UiUtils;

/**
 * 带有底部操作栏的基类
 * 
 * @author Administrator
 * 
 */
public abstract class BaseDetailsActivity extends BaseActivity {
	
	@Override
	protected void initView() {
		FrameLayout fl = (FrameLayout) findViewById(R.id.fl_basedetail_content);
		fl.addView(mLp);
		mLp.onlySuccessView(onlySuccessView());
		
		// 替换fragment
		// 将侧滑栏的fragment替换到侧滑栏的容器的布局文件中
		android.support.v4.app.FragmentTransaction transaction = getSupportFragmentManager()
				.beginTransaction();
		Fragment bottomControlFragement = bottomControlFragement();
		if (bottomControlFragement == null) {
			throw new NullPointerException();
		}

		transaction.replace(R.id.fl_basedetail_bottomControl,
				bottomControlFragement);
		transaction.commit();

		
	}
//
//	BaseFragment loadFragment = new BaseFragment() {
//		@Override
//		public int getLayoutId() {
//			return R.layout.framepager;
//		}
//
//		@Override
//		public void initView(View view) {
//			FrameLayout fl = (FrameLayout) view.findViewById(R.id.fl);
//			fl.addView(mLp);
//			mLp.onlySuccessView(onlySuccessView());
//		}
//	};

	public LoadingPager mLp = new LoadingPager(UiUtils.getContext()) {

		@Override
		public ResultCode initNetData() {
			ResultCode resultCode = BaseDetailsActivity.this.initNetData();
			return resultCode;
		}

		@Override
		public View LoadSuccessView() {
			return BaseDetailsActivity.this.loadSuccessView();
		}
	};

	protected abstract Fragment bottomControlFragement();

	protected boolean onlySuccessView() {
		return false;
	}

	protected abstract View loadSuccessView();

	protected abstract ResultCode initNetData();

	@Override
	protected int getLayoutId() {
		return R.layout.activity_basedetail;
	}

	@Override
	protected void initData() {
		mLp.initData();
	}

	@Override
	protected CharSequence getBackActionBarTitle() {
		return UiUtils.getString(R.string.actionbar_title_news);
	}

}
